package org.example.curriculum_design_6_16.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.curriculum_design_6_16.entity.pojo.CompetitionCatalog;
import org.example.curriculum_design_6_16.entity.pojo.CompetitionParticipation;

import java.util.List;

@Mapper
public interface CompetitionCatalogMapper extends BaseMapper<CompetitionCatalog> {

    @Insert("INSERT INTO competition_catalog(competition_name, organizer, level, category, is_official, is_team_competition, " +
            "first_prize_score, second_prize_score, third_prize_score, special_prize_handling, special_prize_score, " +
            "effective_date, description) " +
            "VALUES(#{competitionName}, #{organizer}, #{level}, #{category}, #{isOfficial}, #{isTeamCompetition}, " +
            "#{firstPrizeScore}, #{secondPrizeScore}, #{thirdPrizeScore}, #{specialPrizeHandling}, #{specialPrizeScore}, " +
            "#{effectiveDate}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(CompetitionCatalog competitionCatalog);

    @Update("UPDATE competition_catalog SET competition_name=#{competitionName}, organizer=#{organizer}, level=#{level}, " +
            "category=#{category}, is_official=#{isOfficial}, is_team_competition=#{isTeamCompetition}, " +
            "first_prize_score=#{firstPrizeScore}, second_prize_score=#{secondPrizeScore}, " +
            "third_prize_score=#{thirdPrizeScore}, special_prize_handling=#{specialPrizeHandling}, " +
            "special_prize_score=#{specialPrizeScore}, effective_date=#{effectiveDate}, description=#{description} " +
            "WHERE id=#{id}")
    int update(CompetitionCatalog competitionCatalog);

    @Delete("DELETE FROM competition_catalog WHERE id=#{id}")
    int delete(Integer id);

    @Select("SELECT * FROM competition_catalog WHERE id=#{id}")
    CompetitionCatalog selectById(Integer id);

    @Select("SELECT competitionName FROM competition_catalog WHERE id=#{id}")
    CompetitionCatalog selectNameById(Integer id);

    @Select("SELECT * FROM competition_catalog WHERE competition_name=#{competitionName}")
    CompetitionCatalog selectByName(String competitionName);

    @Select("SELECT * FROM competition_catalog")
    List<CompetitionCatalog> selectAll();

    @Select("SELECT competition_id FROM competition_catalog WHERE competition_name=#{competitionName}")
    Integer selectIdByName(String competitionName);

    @Select("SELECT * FROM competition_catalog WHERE level=#{level} AND category=#{category}")
    List<CompetitionCatalog> selectByLevelAndCategory(@Param("level") String level, @Param("category") String category);
}